package com.example.lenovo.myapplication;

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTabHost;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

public class layoutActivity extends AppCompatActivity {
    private FragmentTabHost tabHost;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layout);

        init();
        setTab();
    }




    //初始化tab框架内容
    public void init() {
        tabHost=(FragmentTabHost)findViewById(R.id.tabHost);
    }

    //创建标签
    public void setTab() {
        FragmentManager fragmentManager=getSupportFragmentManager();
        //设置标签
        tabHost.setup(this,fragmentManager,R.id.tablocation);
        tabHost.getTabWidget().setDividerDrawable(null);
        //创建tab标签
        tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator(setTabView("实时环境")),ceshi2.class,null);
        tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator(setTabView("设备控制")),ceshi2.class,null);
        tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator(setTabView("数据分析")),ceshi2.class,null);
        tabHost.addTab(tabHost.newTabSpec("tab4").setIndicator(setTabView("参数设置")),ceshi5.class,null);
        }
    //利用模板创建页面
    public View setTabView (String title) {
        //利用模板视图创建页面
        View view2=LayoutInflater.from(this).inflate(R.layout.tabtool,null );//tabtool是模板
        //获取文本框中的内容
        TextView textView=(TextView)view2.findViewById(R.id.tabtool_textview_title);
        textView.setText( title );
        return view2;
        }
    }
